Quick Reference

Contents|Index|Previous|Next
Quick reference

This documentation summarizes the directives, text manipulation functions, and special variables which GNU make understands. See Special built-in target names, Catalogue of implicit rules, and Summary of options for other discusssions.

The following is a summary of the directives GNU make recognizes.

define variable
endef

Define a multi-line, recursively-expanded variable.
See Defining canned command sequences.

ifdef variable
ifndef variable
ifeq (a,b)
ifeq "a" "b"
ifeq 'a' 'b'
ifneq (a,b)
ifneq "a" "b"
ifneq 'a' 'b'
else
endif

Conditionally evaluate part of the makefile. See Conditional parts of makefiles.

include file

Include another makefile. See Including other makefiles.

override variable= value
override variable:= value
override variable+= value
override define variable
endef

Define a variable, overriding any previous definition, even one from the command line. See The override directive.

export

Tell `make` to export all variables to child processes by default. See Communicating variables to a sub-make.

export variable
export variable= value
export variable:= value
export variable+= value
unexport variable

Tell make whether or not to export a particular variable to child processes. See communicating variables to a sub-make.

vpath pattern path

Specify a search path for files matching a ‘%’ pattern. See The vpath directive.

vpath pattern

Remove all search paths previously specified for pattern.

vpath

Remove all search paths previously specified in any vpath directive.

The following is a summary of the text manipulation functions (see Functions for transforming text).

$(subst from, to, text)

Replace from with to in text. See Functions for string substitution and analysis.

$(patsubst pattern, replacement, text)

Replace words matching pattern with replacement in text. See Functions for string substitution and analysis.

$(strip string)

Remove excess whitespace characters from string. See Functions for string substitution and analysis.

$(findstring find, text)

Locate find in text. See Functions for string substitution and analysis.

$(filter pattern...,text)

Select words in text that match one of the pattern words. See Functions for string substitution and analysis.

$(filter-out pattern...,text)

Select words in text that do not match any of the pattern words. See Functions for string substitution and analysis.

$(sort list)

Sort the words in list lexicographically, removing duplicates. See Functions for string substitution and analysis.

$(dir names...)

Extract the directory part of each file name. See Functions for file names.

$(notdir names...)

Extract the non-directory part of each file name. See Functions for file names.

$(suffix names...)

Extract the suffix (the last ‘.’ and following characters) of each file name. See Functions for file names.

$(basename names...)

Extract the base name (name without suffix) of each file name. See Functions for file names.

$(addsuffix suffix, names...)

Append suffix to each word in names. See Functions for file names.

$(addprefix prefix, names...)

Prepend prefix to each word in names. See Functions for file names.

$(join list1, list2)

Join two parallel lists of words. See Functions for file names.

$(word n, text)

Extract the nth word (one-origin) of text. See Functions for file names.

$(words text)

Count the number of words in text. Functions for file names.

$(firstword names ...)

Extract the first word of names. See Functions for file names.

$(wildcard pattern ...)

Find file names matching a shell file name, pattern (not a ‘%’ pattern). See The function, wildcard.

$(shell command)

Execute a shell command and return its output. See The shell function.

$(origin variable)

Return a string describing how the make variable, variable, was defined. See The origin function.

$(foreach var, words, text)

Evaluate text with var bound to each word in words, and concatenate the results. See The foreach function.

The following is a summary of the automatic variables. See Automatic variables for full information.

$@

The file name of the target.

$%

The target member name, when the target is an archive member.

$<

The name of the first dependency.

$?

The names of all the dependencies that are newer than the target, with spaces between them. For dependencies which are archive members, only the member named is used (see Using make to update archive files).

$ˆ
$+

The names of all the dependencies with spaces between them. For dependencies which are archive members, only the member named is used (see Using make to update archive files). The value of $ˆ omits duplicate dependencies while $+ retains them and preserves their order.

$*

The stem with which an implicit rule matches (see How patterns match).

$(@D)
$(@F)

The directory part and the file-within-directory part of $@.

$(*D)
$(*F)

The directory part and the file-within-directory part of $*.

$(%D)
$(%F)

The directory part and the file-within-directory part of $%.

$(<D)
$(<F)

The directory part and the file-within-directory part of $<.

$(ˆD)
$(ˆF)

The directory part and the file-within-directory part of $ˆ.

$(+D)
$(+F)

The directory part and the file-within-directory part of $+.

$(?D)
$(?F)

The directory part and the file-within-directory part of $?.

The following variables are used specially by GNU make

MAKEFILES

Makefiles to be read on every invocation of make. See The variable, MAKEFILES.

VPATH

Directory search path for files not found in the current directory.

See VPATH: search path for all dependencies.

SHELL

The name of the system default command interpreter, usually ‘/bin/sh’. You can set SHELL in the makefile to change the shell used to run commands. See Command execution.

MAKE

The name with which make was invoked. Using this variable in commands has special meaning. See How the MAKE variable works.

MAKELEVEL

The number of levels of recursion (sub-makes). See Communicating variables to a sub-make.

MAKEFLAGS

The flags given to make. You can set this in the environment or a makefile to set flags. Communicating variables to a sub-make.

SUFFIXES

The default list of suffixes before make reads any makefiles.

Top|Contents|Index|Previous|Next